<!DOCTYPE html>
<html>
    <head lang="en">
        <meta charset="UTF-8">
        <meta name="csrf-token" content="{{ csrf_token() }}">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 
        <link rel="shortcut icon" type="image/x-icon" href="{{URL::asset('handan/images/logo-icon.png')}}" />
        <title>订阅历史</title>
        <link rel="stylesheet" href="{{URL::asset('newmobile/css/public.css') }}"/>
        <link rel="stylesheet" href="{{URL::asset('newmobile/css/newhistoryfollow.css') }}"/>
        <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
        <script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
        <script src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
        <script src="{{URL::asset('newmobile/js/public.js') }}"></script>
    </head>
<body>

<div class="page-group">
    <div id="page-infinite-scroll-bottom" class="page">
        <div class="content infinite-scroll" data-distance="100">
            <div class="list-block">
                <ul class="list-container">
                    <!--<li></li>-->
                </ul>
            </div>
            <!-- 加载提示符 -->
            <div class="infinite-scroll-preloader">
                <div class="preloader">
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    //收缩详情
    
    var pagess = 1;
    var allpage = 2;
    var loading = false;
    $(function () {
    'use strict';
    //无限滚动
    $(document).on("pageInit", "#page-infinite-scroll-bottom", function(e, id, page) {
        
        // 每次加载添加多少条目
        var itemsPerLoad = 10;
        // 最多可加载的条目
        var lastIndex = $('.list-container li').length;
        pullupRefresh(0); //先加载一次数据
        $(page).on('infinite', function() {
            // 如果正在加载，则退出
            if (loading) return;
            // 设置flag
            loading = true;
            // 模拟1s的加载过程
            setTimeout(function() {
                // 重置加载flag
                loading = false;
                if (pagess >= allpage) {
                    // 加载完毕，则注销无限加载事件，以防不必要的加载
                    $.detachInfiniteScroll($('.infinite-scroll'));
                    // 删除加载提示符
                    $('.infinite-scroll-preloader').html('已加载全部');
                    return;
                }
                pagess++; //页面+1
                pullupRefresh(0);//更新数据
                // 更新最后加载的序号
                lastIndex = $('.list-container li').length;
                $.refreshScroller();
            }, 1000);
        });
    });
    //加载提示符
    $(document).on("pageInit", "#page-preloader", function(e, id, page) {
        $(page).on('click','.open-preloader-title', function () {
            $.showPreloader('加载中...')
            setTimeout(function () {
                $.hidePreloader();
            }, 2000);
        });
        $(page).on('click','.open-indicator', function () {
            $.showIndicator();
            setTimeout(function () {
                $.hideIndicator();
            }, 2000);
        });
    });
    $.init();
});
//数据加载
var listurl       = '{{url("/newhistoryfollow")}}';
function pullupRefresh(num){
    var id  = "{{$id}}";
    $.ajax({
        url: listurl,
        type: "get",
        data:  {id:id,page:pagess,pagetype:1},
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        dataType:'json',
        success: function (data) {
            allpage = data.totalpage;
            if(allpage < 2){
                $('.infinite-scroll-preloader').html('已加载全部');
            }else{
                $('.infinite-scroll-preloader').html('<div class="preloader"></div>');
            }
            var str='';
            var dataArr = data.historyfollowdata;
                if(data){
                    for(var i=0;i<dataArr.length;i++) {
                        var data = dataArr;
                        console.log(data[i]);
                        str+='<li onclick="langxue(this)"><section class="newhistoryfollow">';
                        str+='<div class="l_master_title"><section>';
                        str+='<div class="photo">';
                        if(data[i].photo){
                            str+='<img src="'+data[i].photo+'" alt="">';
                        }else{
                            str+='<img src="{{URL::asset('ucenter/images/head.png')}}" alt="">';
                        }
                        
                        str+='</div><div class="uname"><div class="name">'+data[i].username+'</div>';
                        if(data[i].authstatus == 2){
                            str+='<div class="img"><span><img src="{{ URL::asset('newmobile/images/new_analyst/r_master.png') }}" alt=""></span>';
                            str+='<span>认证大师</span></div>';
                        }else{
                            str+='<div class="img"><span><img src="{{ URL::asset('newmobile/images/new_analyst/t_star.png') }}" alt=""></span>';
                            str+='<span>明日之星</span></div>';
                        }                          
                        str+='</div><div class="dan"><div class="danInfo"><span>';
                        if(data[i].direction == 0){
                            str+='正向';
                        }else {
                            str+='反向';
                        }
                        
                        str+='</span></div></div>';        
                        str+='<div class="dan profit"><div class="danInfo">';
                        if(data[i].zong_final_point == null){
                            str+='<p style="color: #cbdde9;">0</p>';
                        }else if(data[i].zong_final_point > 0){
                            str+='<p>'+(data[i].zong_final_point).toFixed(2)+'</p>';
                        }else{
                            str+='<p style="color: #36da2e;">'+(data[i].zong_final_point).toFixed(2)+'</p>';
                        }
                        str+='<p>收益</p></div></div></section></div>';
                        str+='<div class="l_master_detail"><div class="detail"><div><p class="num">'+data[i].dealcounts+'</p><p class="txt">累计交易</p></div>';
                        str+='<div>';
                        if(data[i].max_final_point == null){
                            str+='<p class="num">0</p>';
                        }else {
                            str+='<p class="num">'+(data[i].max_final_point).toFixed(2)+'</p>';
                        }
                        
                        str+='<p class="txt">最大盈利</p></div><div>';
                        if(data[i].min_final_point == null){
                            str+='<p class="num">0</p>';
                        }else {
                            str+='<p class="num">'+(data[i].min_final_point).toFixed(2)+'</p>';
                        }
                        str+='<p class="txt">最大亏损</p></div><div>';
                        if(data[i].avg_final_point == null){
                            str+='<p class="num">0</p>';
                        }else {
                            str+='<p class="num">'+(data[i].avg_final_point).toFixed(2)+'</p>';
                        }
                        str+='<p class="txt">单均</p></div></div></div>'; 
                        str+='</section></li>';     
                    }
                }else{
                    $('.list-container').html('sorry，没有更多数据了');
                }
                console.log(str);
                if(num == 1){
                    $('.list-container').html(str);
                }else{
                    $('.list-container').append(str);
                }
            }
        });
};
//时间转换方法
function UnixToDate(unixTime, isFull, timeZone,type) {
    if (typeof (timeZone) == 'number')
    {
        unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
    }
    var time = new Date(unixTime * 1000);
    var ymdhis = "";
    if(type){
        ymdhis += time.getFullYear() + ".";
        ymdhis += (time.getMonth()+1)>9?(time.getMonth()+1)+'.':'0'+(time.getMonth()+1) + ".";
        ymdhis += time.getDate()>9?time.getDate():'0'+time.getDate();
    }
    if (isFull === true)
    {
        ymdhis += " " + time.getHours()>9?time.getHours()+ ":":'0'+time.getHours() + ":";
        ymdhis += time.getMinutes()>9?time.getMinutes()+ ":":'0'+time.getMinutes() + ":";
        ymdhis += time.getSeconds()>9?time.getSeconds():'0'+time.getSeconds();
    }
    return ymdhis;
}
function langxue(obj) {
    $(obj).find('.l_master_detail').toggle();
}
</script>
</body>
</html>
<style>
    .page, .page-group {
        background: #171922;
    }
    .list-block {
        margin: 0;
    }
    .list-block ul {
        background: #171922;
    }
    .infinite-scroll-preloader {
        color: #cbdde9;
        font-size: 0.63rem;
        margin-top: 1rem;
    }
    body section div.detail div.detail_top div.detail_top_right div p {
        line-height: 1rem;
        font-size: 0.554rem;
        color: #7390a4;
        display: inline-block;
    }
    body section div.list {
        line-height: 1rem;
    }
    p {
        margin: 0;
    }
</style>
